package com.easy.modules.sysmgr.entity;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import com.easy.modules.common.RecordEntity;

/**
 * 角色表，基本权限的集合。无上级与下级之分
 * 创建者： 杨浩泉
 * 创建时间： 2014-3-17 下午9:21:03
 * 版本号： v1.0
 */
@Entity
@Table(name = "EASY_SYSMGR_PERMITS")
@DynamicUpdate(true)
@DynamicInsert(true)
public class PermitsEntity extends RecordEntity {

	private String name ;		//名称
	
	private String remark ;		//备注
	
	private Set<MenuEntity> menus = new HashSet<MenuEntity>(0) ;								//菜单资源
	
	private Set<UserEntity> users = new HashSet<UserEntity>(0) ;								//用户
	
	private Set<UserWorkGroupEntity> workgroups = new HashSet<UserWorkGroupEntity>(0) ;			//用户工作组
	
	private Set<UserRoleEntity> userroles = new HashSet<UserRoleEntity>(0) ;					//用户角色
	
	

	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "EASY_SYSMGR_WORKGROUP_PERMITS", joinColumns = { @JoinColumn(name = "PERMITS_ID", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "WORKGROUP_ID", nullable = false, updatable = false) })
	public Set<UserWorkGroupEntity> getWorkgroups() {
		return workgroups;
	}

	public void setWorkgroups(Set<UserWorkGroupEntity> workgroups) {
		this.workgroups = workgroups;
	}

	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "EASY_SYSMGR_USERROLE_PERMITS", joinColumns = { @JoinColumn(name = "PERMITS_ID", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "USERROLE_ID", nullable = false, updatable = false) })
	public Set<UserRoleEntity> getUserroles() {
		return userroles;
	}

	public void setUserroles(Set<UserRoleEntity> userroles) {
		this.userroles = userroles;
	}

	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "EASY_SYSMGR_USER_PERMITS", joinColumns = { @JoinColumn(name = "PERMITS_ID", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "USER_ID", nullable = false, updatable = false) })
	public Set<UserEntity> getUsers() {
		return users;
	}

	public void setUsers(Set<UserEntity> users) {
		this.users = users;
	}

	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "EASY_SYSMGR_PERMITS_MENUS", joinColumns = { @JoinColumn(name = "PERMITS_ID", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "MENU_ID", nullable = false, updatable = false) })
	public Set<MenuEntity> getMenus() {
		return menus;
	}
	
	public void setMenus(Set<MenuEntity> menus) {
		this.menus = menus;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}
	
	
}
